package com.thrd.taiexhibition.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.thrd.taiexhibition.R;
import com.thrd.taiexhibition.bean.BeanCityIndustryFocus;
import com.thrd.taiexhibition.fresco.FrescoImage;
import com.thrd.taiexhibition.fresco.FrescoUtils;

import java.util.List;

/**
 * @author: ${唐杰}
 * @date: 2021/4/23
 */
public class FocusIndustryView extends LinearLayout {

    private LayoutInflater inflater;
    private FrescoImage mFrescoImage;


    public FocusIndustryView(Context context) {
        this(context,null);
    }

    public FocusIndustryView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public FocusIndustryView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOrientation(VERTICAL);
        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


    }


    public void setData(List<BeanCityIndustryFocus> list){
        removeAllViews();
        if(list!=null){
            for (final BeanCityIndustryFocus beanCityIndustryFocus:list){
                View view = inflater.inflate(R.layout.view_focusindustry, null);
                FrescoImage mFrescoImage=view.findViewById(R.id.fi_image);
                TextView mEnglishName =view.findViewById(R.id.tv_english_name);
                TextView mTitleName=view.findViewById(R.id.tv_title_name);
                TextView mContent=view.findViewById(R.id.tv_content);
                FrescoUtils.getInstance().setPrefixProgressLoad(getContext(), mFrescoImage,beanCityIndustryFocus.getIndustryIcon());
                mEnglishName.setText(beanCityIndustryFocus.getIndustryEnglishName());
                mTitleName.setText(beanCityIndustryFocus.getIndustryName());
                mContent.setText(beanCityIndustryFocus.getIndustryDescribe());
                view.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(onItemImageListener!=null){
                            onItemImageListener.onItemImageListener(beanCityIndustryFocus);
                        }
                    }
                });
                addView(view,LayoutParams.MATCH_PARENT,getResources().getDimensionPixelOffset(R.dimen.qb_px_129));
            }


        }

    }




    public void setAnimention(){
        if(getChildCount()>0){
            for(int i=0;i<getChildCount();i++){
                View view=getChildAt(i);
                TextView mEnglishName =view.findViewById(R.id.tv_english_name);
                TextView mTitleName=view.findViewById(R.id.tv_title_name);
                TextView mContent=view.findViewById(R.id.tv_content);
                FrescoImage mFrescoImage=view.findViewById(R.id.fi_image);
                TextView mView=view.findViewById(R.id.tv_view);
                Animation animation =AnimationUtils.loadAnimation(getContext(),R.anim.focus_industry_item);
                animation.setDuration(500);
                mFrescoImage.startAnimation(animation);

                Animation animation1 =AnimationUtils.loadAnimation(getContext(),R.anim.focus_industry_item);
                animation1.setDuration(1000);
                mEnglishName.startAnimation(animation1);

                Animation animation2 =AnimationUtils.loadAnimation(getContext(),R.anim.focus_industry_item);
                animation2.setDuration(1000);
                mTitleName.startAnimation(animation2);


                Animation animation3 =AnimationUtils.loadAnimation(getContext(),R.anim.focus_industry_item);
                animation3.setDuration(1500);
                mContent.startAnimation(animation3);

                Animation animation4 =AnimationUtils.loadAnimation(getContext(),R.anim.focus_industry_item);
                animation4.setDuration(1000);
                mView.startAnimation(animation4);

                //mFrescoImage.animate().alpha(1).setDuration(2000).start();
            }
        }
    }

    public OnItemImageListener getOnItemImageListener() {
        return onItemImageListener;
    }

    public void setOnItemImageListener(OnItemImageListener onItemImageListener) {
        this.onItemImageListener = onItemImageListener;
    }

    private OnItemImageListener onItemImageListener;

    public interface OnItemImageListener{

        void onItemImageListener(BeanCityIndustryFocus mBeanCityIndustryFocus);
    }
}
